package com.hnu.highlynewapp.app;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.hnu.highlynewapp.entity.FinancialInstitutionInfoEntity;
import com.hnu.highlynewapp.exception.BizCodeEnum;
import com.hnu.highlynewapp.vo.FinancialInstSearchVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.hnu.highlynewapp.entity.ServiceInstitutionInfoEntity;
import com.hnu.highlynewapp.service.ServiceInstitutionInfoService;
import com.hnu.highlynewapp.utils.PageUtils;
import com.hnu.highlynewapp.utils.R;
import springfox.documentation.annotations.ApiIgnore;


/**
 * 服务机构
 *
 * @author hnu_worker
 * @email 825963704@qq.com
 * @date 2021-01-03 10:35:56
 */
@Api(tags = "角色api管理")
@RestController
@RequestMapping("/serviceinstitutioninfo")
public class ServiceInstitutionInfoController {
    @Autowired
    private ServiceInstitutionInfoService serviceInstitutionInfoService;

    /**
     * 根据检索条件获取对应的服务机构列表
     */
    @ApiOperation("根据检索条件获取对应的服务机构列表")
    @PostMapping("/getlist")
    public R getList(@ApiParam("服务类型") @RequestParam("serviceType") String serviceType){
        List<ServiceInstitutionInfoEntity> list = serviceInstitutionInfoService.getListByParma(serviceType);
        return R.ok().put("data", list);
    }

    /**
     * 根据id获取服务机构
     */
    @ApiOperation("根据id获取服务机构")
    @GetMapping("/get/{serviceInstitutionId}")
    public R getById(@PathVariable("serviceInstitutionId") Long serviceInstitutionId){
        ServiceInstitutionInfoEntity service = serviceInstitutionInfoService.getById(serviceInstitutionId);
        if (service == null) {
            return R.error(BizCodeEnum.INFO_NOT_FOUND_EXCEPTION.getCode(), BizCodeEnum.INFO_NOT_FOUND_EXCEPTION.getMessage());
        }
        return R.ok().put("data", service);
    }

    /**
     * 列表
     */
    @ApiIgnore
    @RequestMapping("/list")
    //@RequiresPermissions("highlynewapp:serviceinstitutioninfo:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = serviceInstitutionInfoService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @ApiIgnore
    @RequestMapping("/info/{serviceInstitutionId}")
    //@RequiresPermissions("highlynewapp:serviceinstitutioninfo:info")
    public R info(@PathVariable("serviceInstitutionId") Long serviceInstitutionId){
		ServiceInstitutionInfoEntity serviceInstitutionInfo = serviceInstitutionInfoService.getById(serviceInstitutionId);

        return R.ok().put("serviceInstitutionInfo", serviceInstitutionInfo);
    }

    /**
     * 保存
     */
    @ApiIgnore
    @RequestMapping("/save")
    //@RequiresPermissions("highlynewapp:serviceinstitutioninfo:save")
    public R save(@RequestBody ServiceInstitutionInfoEntity serviceInstitutionInfo){
		serviceInstitutionInfoService.save(serviceInstitutionInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiIgnore
    @RequestMapping("/update")
    //@RequiresPermissions("highlynewapp:serviceinstitutioninfo:update")
    public R update(@RequestBody ServiceInstitutionInfoEntity serviceInstitutionInfo){
		serviceInstitutionInfoService.updateById(serviceInstitutionInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiIgnore
    @RequestMapping("/delete")
    //@RequiresPermissions("highlynewapp:serviceinstitutioninfo:delete")
    public R delete(@RequestBody Long[] serviceInstitutionIds){
		serviceInstitutionInfoService.removeByIds(Arrays.asList(serviceInstitutionIds));

        return R.ok();
    }

}
